package com.zkzx.operation.api.service.authorization;

import com.zkzx.operation.api.mapper.UserMapper;
import com.zkzx.operation.api.mapper.entity.User;
import com.zkzx.operation.api.mapper.entity.UserExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Optional;

/**
 * @author young Email:yanghui@zkraising.com
 * @description
 * @company 北京中科智兴物联科技有限公司 @版权所有
 * @since 2021年04月27日 17时58分
 */
@Service
public class UserMapperService {

    @Resource
    private UserMapper userMapper;

    /**
     * 获取用户信息
     * @param code 用户名称
     * @return 用户信息
     */
    public User getByCode(String code){
        UserExample userExample = new UserExample();
        userExample.createCriteria().andCodeEqualTo(code);
        Optional<User> first = userMapper.selectByExample(userExample).stream().findFirst();
        if (first.isPresent()){
            return first.get();
        }
        return null;
    }
}
